home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Python 1.4 / Python 1.4 source / Mac / Modules / dlg / Dlgmodule.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-23  |  24.8 KB  |  1,015 lines  |  [TEXT/CWIE]

  1.  
  2. /* =========================== Module Dlg =========================== */
  3.  
  4. #include "Python.h"
  5.  
  6.  
  7.  
  8. #define SystemSevenOrLater 1
  9.  
  10. #include "macglue.h"
  11. #include <Memory.h>
  12. #include <Dialogs.h>
  13. #include <Menus.h>
  14. #include <Controls.h>
  15.  
  16. extern PyObject *ResObj_New(Handle);
  17. extern int ResObj_Convert(PyObject *, Handle *);
  18. extern PyObject *OptResObj_New(Handle);
  19. extern int OptResObj_Convert(PyObject *, Handle *);
  20.  
  21. extern PyObject *WinObj_New(WindowPtr);
  22. extern int WinObj_Convert(PyObject *, WindowPtr *);
  23. extern PyTypeObject Window_Type;
  24. #define WinObj_Check(x) ((x)->ob_type == &Window_Type)
  25.  
  26. extern PyObject *DlgObj_New(DialogPtr);
  27. extern int DlgObj_Convert(PyObject *, DialogPtr *);
  28. extern PyTypeObject Dialog_Type;
  29. #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
  30.  
  31. extern PyObject *MenuObj_New(MenuHandle);
  32. extern int MenuObj_Convert(PyObject *, MenuHandle *);
  33.  
  34. extern PyObject *CtlObj_New(ControlHandle);
  35. extern int CtlObj_Convert(PyObject *, ControlHandle *);
  36.  
  37. extern PyObject *GrafObj_New(GrafPtr);
  38. extern int GrafObj_Convert(PyObject *, GrafPtr *);
  39.  
  40. extern PyObject *BMObj_New(BitMapPtr);
  41. extern int BMObj_Convert(PyObject *, BitMapPtr *);
  42.  
  43. extern PyObject *WinObj_WhichWindow(WindowPtr);
  44.  
  45. #include <Dialogs.h>
  46.  
  47. #ifndef HAVE_UNIVERSAL_HEADERS
  48. #define NewModalFilterProc(x) (x)
  49. #endif
  50.  
  51. #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
  52.  
  53. /* XXX Shouldn't this be a stack? */
  54. static PyObject *Dlg_FilterProc_callback = NULL;
  55.  
  56. static PyObject *DlgObj_New(DialogPtr); /* Forward */
  57.  
  58. static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog,
  59.                                          EventRecord *event,
  60.                                          short *itemHit)
  61. {
  62.     Boolean rv;
  63.     PyObject *args, *res;
  64.     PyObject *callback = Dlg_FilterProc_callback;
  65.     if (callback == NULL)
  66.         return 0; /* Default behavior */
  67.     Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
  68.     args = Py_BuildValue("O&O&", WinObj_WhichWindow, dialog, PyMac_BuildEventRecord, event);
  69.     if (args == NULL)
  70.         res = NULL;
  71.     else {
  72.         res = PyEval_CallObject(callback, args);
  73.         Py_DECREF(args);
  74.     }
  75.     if (res == NULL) {
  76.         fprintf(stderr, "Exception in Dialog Filter\n");
  77.         PyErr_Print();
  78.         *itemHit = -1; /* Fake return item */
  79.         return 1; /* We handled it */
  80.     }
  81.     else {
  82.         Dlg_FilterProc_callback = callback;
  83.         if (PyInt_Check(res)) {
  84.             *itemHit = PyInt_AsLong(res);
  85.             rv = 1;
  86.         }
  87.         else
  88.             rv = PyObject_IsTrue(res);
  89.     }
  90.     Py_DECREF(res);
  91.     return rv;
  92. }
  93.  
  94. static ModalFilterProcPtr
  95. Dlg_PassFilterProc(PyObject *callback)
  96. {
  97.     PyObject *tmp = Dlg_FilterProc_callback;
  98.     Dlg_FilterProc_callback = NULL;
  99.     if (callback == Py_None) {
  100.         Py_XDECREF(tmp);
  101.         return NULL;
  102.     }
  103.     Py_INCREF(callback);
  104.     Dlg_FilterProc_callback = callback;
  105.     Py_XDECREF(tmp);
  106.     return &Dlg_UnivFilterProc;
  107. }
  108.  
  109. extern PyMethodChain WinObj_chain;
  110.  
  111. static PyObject *Dlg_Error;
  112.  
  113. /* ----------------------- Object type Dialog ----------------------- */
  114.  
  115. PyTypeObject Dialog_Type;
  116.  
  117. #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
  118.  
  119. typedef struct DialogObject {
  120.     PyObject_HEAD
  121.     DialogPtr ob_itself;
  122. } DialogObject;
  123.  
  124. PyObject *DlgObj_New(itself)
  125.     DialogPtr itself;
  126. {
  127.     DialogObject *it;
  128.     if (itself == NULL) return Py_None;
  129.     it = PyObject_NEW(DialogObject, &Dialog_Type);
  130.     if (it == NULL) return NULL;
  131.     it->ob_itself = itself;
  132.     SetWRefCon(itself, (long)it);
  133.     return (PyObject *)it;
  134. }
  135. DlgObj_Convert(v, p_itself)
  136.     PyObject *v;
  137.     DialogPtr *p_itself;
  138. {
  139.     if (v == Py_None) { *p_itself = NULL; return 1; }
  140.     if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);
  141.                           return 1; }
  142.     if (!DlgObj_Check(v))
  143.     {
  144.         PyErr_SetString(PyExc_TypeError, "Dialog required");
  145.         return 0;
  146.     }
  147.     *p_itself = ((DialogObject *)v)->ob_itself;
  148.     return 1;
  149. }
  150.  
  151. static void DlgObj_dealloc(self)
  152.     DialogObject *self;
  153. {
  154.     DisposeDialog(self->ob_itself);
  155.     PyMem_DEL(self);
  156. }
  157.  
  158. static PyObject *DlgObj_DrawDialog(_self, _args)
  159.     DialogObject *_self;
  160.     PyObject *_args;
  161. {
  162.     PyObject *_res = NULL;
  163.     if (!PyArg_ParseTuple(_args, ""))
  164.         return NULL;
  165.     DrawDialog(_self->ob_itself);
  166.     Py_INCREF(Py_None);
  167.     _res = Py_None;
  168.     return _res;
  169. }
  170.  
  171. static PyObject *DlgObj_UpdateDialog(_self, _args)
  172.     DialogObject *_self;
  173.     PyObject *_args;
  174. {
  175.     PyObject *_res = NULL;
  176.     RgnHandle updateRgn;
  177.     if (!PyArg_ParseTuple(_args, "O&",
  178.                           ResObj_Convert, &updateRgn))
  179.         return NULL;
  180.     UpdateDialog(_self->ob_itself,
  181.                  updateRgn);
  182.     Py_INCREF(Py_None);
  183.     _res = Py_None;
  184.     return _res;
  185. }
  186.  
  187. static PyObject *DlgObj_GetDialogItem(_self, _args)
  188.     DialogObject *_self;
  189.     PyObject *_args;
  190. {
  191.     PyObject *_res = NULL;
  192.     short itemNo;
  193.     short itemType;
  194.     Handle item;
  195.     Rect box;
  196.     if (!PyArg_ParseTuple(_args, "h",
  197.                           &itemNo))
  198.         return NULL;
  199.     GetDialogItem(_self->ob_itself,
  200.                   itemNo,
  201.                   &itemType,
  202.                   &item,
  203.                   &box);
  204.     _res = Py_BuildValue("hO&O&",
  205.                          itemType,
  206.                          OptResObj_New, item,
  207.                          PyMac_BuildRect, &box);
  208.     return _res;
  209. }
  210.  
  211. static PyObject *DlgObj_SetDialogItem(_self, _args)
  212.     DialogObject *_self;
  213.     PyObject *_args;
  214. {
  215.     PyObject *_res = NULL;
  216.     short itemNo;
  217.     short itemType;
  218.     Handle item;
  219.     Rect box;
  220.     if (!PyArg_ParseTuple(_args, "hhO&O&",
  221.                           &itemNo,
  222.                           &itemType,
  223.                           ResObj_Convert, &item,
  224.                           PyMac_GetRect, &box))
  225.         return NULL;
  226.     SetDialogItem(_self->ob_itself,
  227.                   itemNo,
  228.                   itemType,
  229.                   item,
  230.                   &box);
  231.     Py_INCREF(Py_None);
  232.     _res = Py_None;
  233.     return _res;
  234. }
  235.  
  236. static PyObject *DlgObj_HideDialogItem(_self, _args)
  237.     DialogObject *_self;
  238.     PyObject *_args;
  239. {
  240.     PyObject *_res = NULL;
  241.     short itemNo;
  242.     if (!PyArg_ParseTuple(_args, "h",
  243.                           &itemNo))
  244.         return NULL;
  245.     HideDialogItem(_self->ob_itself,
  246.                    itemNo);
  247.     Py_INCREF(Py_None);
  248.     _res = Py_None;
  249.     return _res;
  250. }
  251.  
  252. static PyObject *DlgObj_ShowDialogItem(_self, _args)
  253.     DialogObject *_self;
  254.     PyObject *_args;
  255. {
  256.     PyObject *_res = NULL;
  257.     short itemNo;
  258.     if (!PyArg_ParseTuple(_args, "h",
  259.                           &itemNo))
  260.         return NULL;
  261.     ShowDialogItem(_self->ob_itself,
  262.                    itemNo);
  263.     Py_INCREF(Py_None);
  264.     _res = Py_None;
  265.     return _res;
  266. }
  267.  
  268. static PyObject *DlgObj_SelectDialogItemText(_self, _args)
  269.     DialogObject *_self;
  270.     PyObject *_args;
  271. {
  272.     PyObject *_res = NULL;
  273.     short itemNo;
  274.     short strtSel;
  275.     short endSel;
  276.     if (!PyArg_ParseTuple(_args, "hhh",
  277.                           &itemNo,
  278.                           &strtSel,
  279.                           &endSel))
  280.         return NULL;
  281.     SelectDialogItemText(_self->ob_itself,
  282.                          itemNo,
  283.                          strtSel,
  284.                          endSel);
  285.     Py_INCREF(Py_None);
  286.     _res = Py_None;
  287.     return _res;
  288. }
  289.  
  290. static PyObject *DlgObj_FindDialogItem(_self, _args)
  291.     DialogObject *_self;
  292.     PyObject *_args;
  293. {
  294.     PyObject *_res = NULL;
  295.     short _rv;
  296.     Point thePt;
  297.     if (!PyArg_ParseTuple(_args, "O&",
  298.                           PyMac_GetPoint, &thePt))
  299.         return NULL;
  300.     _rv = FindDialogItem(_self->ob_itself,
  301.                          thePt);
  302.     _res = Py_BuildValue("h",
  303.                          _rv);
  304.     return _res;
  305. }
  306.  
  307. static PyObject *DlgObj_DialogCut(_self, _args)
  308.     DialogObject *_self;
  309.     PyObject *_args;
  310. {
  311.     PyObject *_res = NULL;
  312.     if (!PyArg_ParseTuple(_args, ""))
  313.         return NULL;
  314.     DialogCut(_self->ob_itself);
  315.     Py_INCREF(Py_None);
  316.     _res = Py_None;
  317.     return _res;
  318. }
  319.  
  320. static PyObject *DlgObj_DialogPaste(_self, _args)
  321.     DialogObject *_self;
  322.     PyObject *_args;
  323. {
  324.     PyObject *_res = NULL;
  325.     if (!PyArg_ParseTuple(_args, ""))
  326.         return NULL;
  327.     DialogPaste(_self->ob_itself);
  328.     Py_INCREF(Py_None);
  329.     _res = Py_None;
  330.     return _res;
  331. }
  332.  
  333. static PyObject *DlgObj_DialogCopy(_self, _args)
  334.     DialogObject *_self;
  335.     PyObject *_args;
  336. {
  337.     PyObject *_res = NULL;
  338.     if (!PyArg_ParseTuple(_args, ""))
  339.         return NULL;
  340.     DialogCopy(_self->ob_itself);
  341.     Py_INCREF(Py_None);
  342.     _res = Py_None;
  343.     return _res;
  344. }
  345.  
  346. static PyObject *DlgObj_DialogDelete(_self, _args)
  347.     DialogObject *_self;
  348.     PyObject *_args;
  349. {
  350.     PyObject *_res = NULL;
  351.     if (!PyArg_ParseTuple(_args, ""))
  352.         return NULL;
  353.     DialogDelete(_self->ob_itself);
  354.     Py_INCREF(Py_None);
  355.     _res = Py_None;
  356.     return _res;
  357. }
  358.  
  359. static PyObject *DlgObj_AppendDITL(_self, _args)
  360.     DialogObject *_self;
  361.     PyObject *_args;
  362. {
  363.     PyObject *_res = NULL;
  364.     Handle theHandle;
  365.     DITLMethod method;
  366.     if (!PyArg_ParseTuple(_args, "O&h",
  367.                           ResObj_Convert, &theHandle,
  368.                           &method))
  369.         return NULL;
  370.     AppendDITL(_self->ob_itself,
  371.                theHandle,
  372.                method);
  373.     Py_INCREF(Py_None);
  374.     _res = Py_None;
  375.     return _res;
  376. }
  377.  
  378. static PyObject *DlgObj_CountDITL(_self, _args)
  379.     DialogObject *_self;
  380.     PyObject *_args;
  381. {
  382.     PyObject *_res = NULL;
  383.     short _rv;
  384.     if (!PyArg_ParseTuple(_args, ""))
  385.         return NULL;
  386.     _rv = CountDITL(_self->ob_itself);
  387.     _res = Py_BuildValue("h",
  388.                          _rv);
  389.     return _res;
  390. }
  391.  
  392. static PyObject *DlgObj_ShortenDITL(_self, _args)
  393.     DialogObject *_self;
  394.     PyObject *_args;
  395. {
  396.     PyObject *_res = NULL;
  397.     short numberItems;
  398.     if (!PyArg_ParseTuple(_args, "h",
  399.                           &numberItems))
  400.         return NULL;
  401.     ShortenDITL(_self->ob_itself,
  402.                 numberItems);
  403.     Py_INCREF(Py_None);
  404.     _res = Py_None;
  405.     return _res;
  406. }
  407.  
  408. static PyObject *DlgObj_StdFilterProc(_self, _args)
  409.     DialogObject *_self;
  410.     PyObject *_args;
  411. {
  412.     PyObject *_res = NULL;
  413.     Boolean _rv;
  414.     EventRecord event;
  415.     short itemHit;
  416.     if (!PyArg_ParseTuple(_args, ""))
  417.         return NULL;
  418.     _rv = StdFilterProc(_self->ob_itself,
  419.                         &event,
  420.                         &itemHit);
  421.     _res = Py_BuildValue("bO&h",
  422.                          _rv,
  423.                          PyMac_BuildEventRecord, &event,
  424.                          itemHit);
  425.     return _res;
  426. }
  427.  
  428. static PyObject *DlgObj_SetDialogDefaultItem(_self, _args)
  429.     DialogObject *_self;
  430.     PyObject *_args;
  431. {
  432.     PyObject *_res = NULL;
  433.     OSErr _err;
  434.     short newItem;
  435.     if (!PyArg_ParseTuple(_args, "h",
  436.                           &newItem))
  437.         return NULL;
  438.     _err = SetDialogDefaultItem(_self->ob_itself,
  439.                                 newItem);
  440.     if (_err != noErr) return PyMac_Error(_err);
  441.     Py_INCREF(Py_None);
  442.     _res = Py_None;
  443.     return _res;
  444. }
  445.  
  446. static PyObject *DlgObj_SetDialogCancelItem(_self, _args)
  447.     DialogObject *_self;
  448.     PyObject *_args;
  449. {
  450.     PyObject *_res = NULL;
  451.     OSErr _err;
  452.     short newItem;
  453.     if (!PyArg_ParseTuple(_args, "h",
  454.                           &newItem))
  455.         return NULL;
  456.     _err = SetDialogCancelItem(_self->ob_itself,
  457.                                newItem);
  458.     if (_err != noErr) return PyMac_Error(_err);
  459.     Py_INCREF(Py_None);
  460.     _res = Py_None;
  461.     return _res;
  462. }
  463.  
  464. static PyObject *DlgObj_SetDialogTracksCursor(_self, _args)
  465.     DialogObject *_self;
  466.     PyObject *_args;
  467. {
  468.     PyObject *_res = NULL;
  469.     OSErr _err;
  470.     Boolean tracks;
  471.     if (!PyArg_ParseTuple(_args, "b",
  472.                           &tracks))
  473.         return NULL;
  474.     _err = SetDialogTracksCursor(_self->ob_itself,
  475.                                  tracks);
  476.     if (_err != noErr) return PyMac_Error(_err);
  477.     Py_INCREF(Py_None);
  478.     _res = Py_None;
  479.     return _res;
  480. }
  481.  
  482. static PyObject *DlgObj_GetDialogWindow(_self, _args)
  483.     DialogObject *_self;
  484.     PyObject *_args;
  485. {
  486.     PyObject *_res = NULL;
  487.     DialogPtr _rv;
  488.     if (!PyArg_ParseTuple(_args, ""))
  489.         return NULL;
  490.     _rv = GetDialogWindow(_self->ob_itself);
  491.     _res = Py_BuildValue("O&",
  492.                          WinObj_WhichWindow, _rv);
  493.     return _res;
  494. }
  495.  
  496. static PyObject *DlgObj_GetDialogDefaultItem(_self, _args)
  497.     DialogObject *_self;
  498.     PyObject *_args;
  499. {
  500.     PyObject *_res = NULL;
  501.     SInt16 _rv;
  502.     if (!PyArg_ParseTuple(_args, ""))
  503.         return NULL;
  504.     _rv = GetDialogDefaultItem(_self->ob_itself);
  505.     _res = Py_BuildValue("h",
  506.                          _rv);
  507.     return _res;
  508. }
  509.  
  510. static PyObject *DlgObj_GetDialogCancelItem(_self, _args)
  511.     DialogObject *_self;
  512.     PyObject *_args;
  513. {
  514.     PyObject *_res = NULL;
  515.     SInt16 _rv;
  516.     if (!PyArg_ParseTuple(_args, ""))
  517.         return NULL;
  518.     _rv = GetDialogCancelItem(_self->ob_itself);
  519.     _res = Py_BuildValue("h",
  520.                          _rv);
  521.     return _res;
  522. }
  523.  
  524. static PyObject *DlgObj_GetDialogKeyboardFocusItem(_self, _args)
  525.     DialogObject *_self;
  526.     PyObject *_args;
  527. {
  528.     PyObject *_res = NULL;
  529.     SInt16 _rv;
  530.     if (!PyArg_ParseTuple(_args, ""))
  531.         return NULL;
  532.     _rv = GetDialogKeyboardFocusItem(_self->ob_itself);
  533.     _res = Py_BuildValue("h",
  534.                          _rv);
  535.     return _res;
  536. }
  537.  
  538. static PyObject *DlgObj_SetGrafPortOfDialog(_self, _args)
  539.     DialogObject *_self;
  540.     PyObject *_args;
  541. {
  542.     PyObject *_res = NULL;
  543.     if (!PyArg_ParseTuple(_args, ""))
  544.         return NULL;
  545.     SetGrafPortOfDialog(_self->ob_itself);
  546.     Py_INCREF(Py_None);
  547.     _res = Py_None;
  548.     return _res;
  549. }
  550.  
  551. static PyMethodDef DlgObj_methods[] = {
  552.     {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1,
  553.      "() -> None"},
  554.     {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1,
  555.      "(RgnHandle updateRgn) -> None"},
  556.     {"GetDialogItem", (PyCFunction)DlgObj_GetDialogItem, 1,
  557.      "(short itemNo) -> (short itemType, Handle item, Rect box)"},
  558.     {"SetDialogItem", (PyCFunction)DlgObj_SetDialogItem, 1,
  559.      "(short itemNo, short itemType, Handle item, Rect box) -> None"},
  560.     {"HideDialogItem", (PyCFunction)DlgObj_HideDialogItem, 1,
  561.      "(short itemNo) -> None"},
  562.     {"ShowDialogItem", (PyCFunction)DlgObj_ShowDialogItem, 1,
  563.      "(short itemNo) -> None"},
  564.     {"SelectDialogItemText", (PyCFunction)DlgObj_SelectDialogItemText, 1,
  565.      "(short itemNo, short strtSel, short endSel) -> None"},
  566.     {"FindDialogItem", (PyCFunction)DlgObj_FindDialogItem, 1,
  567.      "(Point thePt) -> (short _rv)"},
  568.     {"DialogCut", (PyCFunction)DlgObj_DialogCut, 1,
  569.      "() -> None"},
  570.     {"DialogPaste", (PyCFunction)DlgObj_DialogPaste, 1,
  571.      "() -> None"},
  572.     {"DialogCopy", (PyCFunction)DlgObj_DialogCopy, 1,
  573.      "() -> None"},
  574.     {"DialogDelete", (PyCFunction)DlgObj_DialogDelete, 1,
  575.      "() -> None"},
  576.     {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1,
  577.      "(Handle theHandle, DITLMethod method) -> None"},
  578.     {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1,
  579.      "() -> (short _rv)"},
  580.     {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1,
  581.      "(short numberItems) -> None"},
  582.     {"StdFilterProc", (PyCFunction)DlgObj_StdFilterProc, 1,
  583.      "() -> (Boolean _rv, EventRecord event, short itemHit)"},
  584.     {"SetDialogDefaultItem", (PyCFunction)DlgObj_SetDialogDefaultItem, 1,
  585.      "(short newItem) -> None"},
  586.     {"SetDialogCancelItem", (PyCFunction)DlgObj_SetDialogCancelItem, 1,
  587.      "(short newItem) -> None"},
  588.     {"SetDialogTracksCursor", (PyCFunction)DlgObj_SetDialogTracksCursor, 1,
  589.      "(Boolean tracks) -> None"},
  590.     {"GetDialogWindow", (PyCFunction)DlgObj_GetDialogWindow, 1,
  591.      "() -> (DialogPtr _rv)"},
  592.     {"GetDialogDefaultItem", (PyCFunction)DlgObj_GetDialogDefaultItem, 1,
  593.      "() -> (SInt16 _rv)"},
  594.     {"GetDialogCancelItem", (PyCFunction)DlgObj_GetDialogCancelItem, 1,
  595.      "() -> (SInt16 _rv)"},
  596.     {"GetDialogKeyboardFocusItem", (PyCFunction)DlgObj_GetDialogKeyboardFocusItem, 1,
  597.      "() -> (SInt16 _rv)"},
  598.     {"SetGrafPortOfDialog", (PyCFunction)DlgObj_SetGrafPortOfDialog, 1,
  599.      "() -> None"},
  600.     {NULL, NULL, 0}
  601. };
  602.  
  603. PyMethodChain DlgObj_chain = { DlgObj_methods, &WinObj_chain };
  604.  
  605. static PyObject *DlgObj_getattr(self, name)
  606.     DialogObject *self;
  607.     char *name;
  608. {
  609.     return Py_FindMethodInChain(&DlgObj_chain, (PyObject *)self, name);
  610. }
  611.  
  612. #define DlgObj_setattr NULL
  613.  
  614. PyTypeObject Dialog_Type = {
  615.     PyObject_HEAD_INIT(&PyType_Type)
  616.     0, /*ob_size*/
  617.     "Dialog", /*tp_name*/
  618.     sizeof(DialogObject), /*tp_basicsize*/
  619.     0, /*tp_itemsize*/
  620.     /* methods */
  621.     (destructor) DlgObj_dealloc, /*tp_dealloc*/
  622.     0, /*tp_print*/
  623.     (getattrfunc) DlgObj_getattr, /*tp_getattr*/
  624.     (setattrfunc) DlgObj_setattr, /*tp_setattr*/
  625. };
  626.  
  627. /* --------------------- End object type Dialog --------------------- */
  628.  
  629.  
  630. static PyObject *Dlg_NewDialog(_self, _args)
  631.     PyObject *_self;
  632.     PyObject *_args;
  633. {
  634.     PyObject *_res = NULL;
  635.     DialogPtr _rv;
  636.     Rect boundsRect;
  637.     Str255 title;
  638.     Boolean visible;
  639.     short procID;
  640.     WindowPtr behind;
  641.     Boolean goAwayFlag;
  642.     long refCon;
  643.     Handle itmLstHndl;
  644.     if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
  645.                           PyMac_GetRect, &boundsRect,
  646.                           PyMac_GetStr255, title,
  647.                           &visible,
  648.                           &procID,
  649.                           WinObj_Convert, &behind,
  650.                           &goAwayFlag,
  651.                           &refCon,
  652.                           ResObj_Convert, &itmLstHndl))
  653.         return NULL;
  654.     _rv = NewDialog((void *)0,
  655.                     &boundsRect,
  656.                     title,
  657.                     visible,
  658.                     procID,
  659.                     behind,
  660.                     goAwayFlag,
  661.                     refCon,
  662.                     itmLstHndl);
  663.     _res = Py_BuildValue("O&",
  664.                          DlgObj_New, _rv);
  665.     return _res;
  666. }
  667.  
  668. static PyObject *Dlg_GetNewDialog(_self, _args)
  669.     PyObject *_self;
  670.     PyObject *_args;
  671. {
  672.     PyObject *_res = NULL;
  673.     DialogPtr _rv;
  674.     short dialogID;
  675.     WindowPtr behind;
  676.     if (!PyArg_ParseTuple(_args, "hO&",
  677.                           &dialogID,
  678.                           WinObj_Convert, &behind))
  679.         return NULL;
  680.     _rv = GetNewDialog(dialogID,
  681.                        (void *)0,
  682.                        behind);
  683.     _res = Py_BuildValue("O&",
  684.                          DlgObj_New, _rv);
  685.     return _res;
  686. }
  687.  
  688. static PyObject *Dlg_ParamText(_self, _args)
  689.     PyObject *_self;
  690.     PyObject *_args;
  691. {
  692.     PyObject *_res = NULL;
  693.     Str255 param0;
  694.     Str255 param1;
  695.     Str255 param2;
  696.     Str255 param3;
  697.     if (!PyArg_ParseTuple(_args, "O&O&O&O&",
  698.                           PyMac_GetStr255, param0,
  699.                           PyMac_GetStr255, param1,
  700.                           PyMac_GetStr255, param2,
  701.                           PyMac_GetStr255, param3))
  702.         return NULL;
  703.     ParamText(param0,
  704.               param1,
  705.               param2,
  706.               param3);
  707.     Py_INCREF(Py_None);
  708.     _res = Py_None;
  709.     return _res;
  710. }
  711.  
  712. static PyObject *Dlg_ModalDialog(_self, _args)
  713.     PyObject *_self;
  714.     PyObject *_args;
  715. {
  716.     PyObject *_res = NULL;
  717.     PyObject* modalFilter;
  718.     short itemHit;
  719.     if (!PyArg_ParseTuple(_args, "O",
  720.                           &modalFilter))
  721.         return NULL;
  722.     ModalDialog(NewModalFilterProc(Dlg_PassFilterProc(modalFilter)),
  723.                 &itemHit);
  724.     _res = Py_BuildValue("h",
  725.                          itemHit);
  726.     return _res;
  727. }
  728.  
  729. static PyObject *Dlg_IsDialogEvent(_self, _args)
  730.     PyObject *_self;
  731.     PyObject *_args;
  732. {
  733.     PyObject *_res = NULL;
  734.     Boolean _rv;
  735.     EventRecord theEvent;
  736.     if (!PyArg_ParseTuple(_args, "O&",
  737.                           PyMac_GetEventRecord, &theEvent))
  738.         return NULL;
  739.     _rv = IsDialogEvent(&theEvent);
  740.     _res = Py_BuildValue("b",
  741.                          _rv);
  742.     return _res;
  743. }
  744.  
  745. static PyObject *Dlg_DialogSelect(_self, _args)
  746.     PyObject *_self;
  747.     PyObject *_args;
  748. {
  749.     PyObject *_res = NULL;
  750.     Boolean _rv;
  751.     EventRecord theEvent;
  752.     DialogPtr theDialog;
  753.     short itemHit;
  754.     if (!PyArg_ParseTuple(_args, "O&",
  755.                           PyMac_GetEventRecord, &theEvent))
  756.         return NULL;
  757.     _rv = DialogSelect(&theEvent,
  758.                        &theDialog,
  759.                        &itemHit);
  760.     _res = Py_BuildValue("bO&h",
  761.                          _rv,
  762.                          WinObj_WhichWindow, theDialog,
  763.                          itemHit);
  764.     return _res;
  765. }
  766.  
  767. static PyObject *Dlg_Alert(_self, _args)
  768.     PyObject *_self;
  769.     PyObject *_args;
  770. {
  771.     PyObject *_res = NULL;
  772.     short _rv;
  773.     short alertID;
  774.     PyObject* modalFilter;
  775.     if (!PyArg_ParseTuple(_args, "hO",
  776.                           &alertID,
  777.                           &modalFilter))
  778.         return NULL;
  779.     _rv = Alert(alertID,
  780.                 NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
  781.     _res = Py_BuildValue("h",
  782.                          _rv);
  783.     return _res;
  784. }
  785.  
  786. static PyObject *Dlg_StopAlert(_self, _args)
  787.     PyObject *_self;
  788.     PyObject *_args;
  789. {
  790.     PyObject *_res = NULL;
  791.     short _rv;
  792.     short alertID;
  793.     PyObject* modalFilter;
  794.     if (!PyArg_ParseTuple(_args, "hO",
  795.                           &alertID,
  796.                           &modalFilter))
  797.         return NULL;
  798.     _rv = StopAlert(alertID,
  799.                     NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
  800.     _res = Py_BuildValue("h",
  801.                          _rv);
  802.     return _res;
  803. }
  804.  
  805. static PyObject *Dlg_NoteAlert(_self, _args)
  806.     PyObject *_self;
  807.     PyObject *_args;
  808. {
  809.     PyObject *_res = NULL;
  810.     short _rv;
  811.     short alertID;
  812.     PyObject* modalFilter;
  813.     if (!PyArg_ParseTuple(_args, "hO",
  814.                           &alertID,
  815.                           &modalFilter))
  816.         return NULL;
  817.     _rv = NoteAlert(alertID,
  818.                     NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
  819.     _res = Py_BuildValue("h",
  820.                          _rv);
  821.     return _res;
  822. }
  823.  
  824. static PyObject *Dlg_CautionAlert(_self, _args)
  825.     PyObject *_self;
  826.     PyObject *_args;
  827. {
  828.     PyObject *_res = NULL;
  829.     short _rv;
  830.     short alertID;
  831.     PyObject* modalFilter;
  832.     if (!PyArg_ParseTuple(_args, "hO",
  833.                           &alertID,
  834.                           &modalFilter))
  835.         return NULL;
  836.     _rv = CautionAlert(alertID,
  837.                        NewModalFilterProc(Dlg_PassFilterProc(modalFilter)));
  838.     _res = Py_BuildValue("h",
  839.                          _rv);
  840.     return _res;
  841. }
  842.  
  843. static PyObject *Dlg_GetDialogItemText(_self, _args)
  844.     PyObject *_self;
  845.     PyObject *_args;
  846. {
  847.     PyObject *_res = NULL;
  848.     Handle item;
  849.     Str255 text;
  850.     if (!PyArg_ParseTuple(_args, "O&",
  851.                           ResObj_Convert, &item))
  852.         return NULL;
  853.     GetDialogItemText(item,
  854.                       text);
  855.     _res = Py_BuildValue("O&",
  856.                          PyMac_BuildStr255, text);
  857.     return _res;
  858. }
  859.  
  860. static PyObject *Dlg_SetDialogItemText(_self, _args)
  861.     PyObject *_self;
  862.     PyObject *_args;
  863. {
  864.     PyObject *_res = NULL;
  865.     Handle item;
  866.     Str255 text;
  867.     if (!PyArg_ParseTuple(_args, "O&O&",
  868.                           ResObj_Convert, &item,
  869.                           PyMac_GetStr255, text))
  870.         return NULL;
  871.     SetDialogItemText(item,
  872.                       text);
  873.     Py_INCREF(Py_None);
  874.     _res = Py_None;
  875.     return _res;
  876. }
  877.  
  878. static PyObject *Dlg_NewColorDialog(_self, _args)
  879.     PyObject *_self;
  880.     PyObject *_args;
  881. {
  882.     PyObject *_res = NULL;
  883.     DialogPtr _rv;
  884.     Rect boundsRect;
  885.     Str255 title;
  886.     Boolean visible;
  887.     short procID;
  888.     WindowPtr behind;
  889.     Boolean goAwayFlag;
  890.     long refCon;
  891.     Handle items;
  892.     if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&",
  893.                           PyMac_GetRect, &boundsRect,
  894.                           PyMac_GetStr255, title,
  895.                           &visible,
  896.                           &procID,
  897.                           WinObj_Convert, &behind,
  898.                           &goAwayFlag,
  899.                           &refCon,
  900.                           ResObj_Convert, &items))
  901.         return NULL;
  902.     _rv = NewColorDialog((void *)0,
  903.                          &boundsRect,
  904.                          title,
  905.                          visible,
  906.                          procID,
  907.                          behind,
  908.                          goAwayFlag,
  909.                          refCon,
  910.                          items);
  911.     _res = Py_BuildValue("O&",
  912.                          DlgObj_New, _rv);
  913.     return _res;
  914. }
  915.  
  916. static PyObject *Dlg_GetAlertStage(_self, _args)
  917.     PyObject *_self;
  918.     PyObject *_args;
  919. {
  920.     PyObject *_res = NULL;
  921.     short _rv;
  922.     if (!PyArg_ParseTuple(_args, ""))
  923.         return NULL;
  924.     _rv = GetAlertStage();
  925.     _res = Py_BuildValue("h",
  926.                          _rv);
  927.     return _res;
  928. }
  929.  
  930. static PyObject *Dlg_ResetAlertStage(_self, _args)
  931.     PyObject *_self;
  932.     PyObject *_args;
  933. {
  934.     PyObject *_res = NULL;
  935.     if (!PyArg_ParseTuple(_args, ""))
  936.         return NULL;
  937.     ResetAlertStage();
  938.     Py_INCREF(Py_None);
  939.     _res = Py_None;
  940.     return _res;
  941. }
  942.  
  943. static PyObject *Dlg_SetDialogFont(_self, _args)
  944.     PyObject *_self;
  945.     PyObject *_args;
  946. {
  947.     PyObject *_res = NULL;
  948.     short value;
  949.     if (!PyArg_ParseTuple(_args, "h",
  950.                           &value))
  951.         return NULL;
  952.     SetDialogFont(value);
  953.     Py_INCREF(Py_None);
  954.     _res = Py_None;
  955.     return _res;
  956. }
  957.  
  958. static PyMethodDef Dlg_methods[] = {
  959.     {"NewDialog", (PyCFunction)Dlg_NewDialog, 1,
  960.      "(Rect boundsRect, Str255 title, Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon, Handle itmLstHndl) -> (DialogPtr _rv)"},
  961.     {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1,
  962.      "(short dialogID, WindowPtr behind) -> (DialogPtr _rv)"},
  963.     {"ParamText", (PyCFunction)Dlg_ParamText, 1,
  964.      "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"},
  965.     {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1,
  966.      "(PyObject* modalFilter) -> (short itemHit)"},
  967.     {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1,
  968.      "(EventRecord theEvent) -> (Boolean _rv)"},
  969.     {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1,
  970.      "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, short itemHit)"},
  971.     {"Alert", (PyCFunction)Dlg_Alert, 1,
  972.      "(short alertID, PyObject* modalFilter) -> (short _rv)"},
  973.     {"StopAlert", (PyCFunction)Dlg_StopAlert, 1,
  974.      "(short alertID, PyObject* modalFilter) -> (short _rv)"},
  975.     {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1,
  976.      "(short alertID, PyObject* modalFilter) -> (short _rv)"},
  977.     {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1,
  978.      "(short alertID, PyObject* modalFilter) -> (short _rv)"},
  979.     {"GetDialogItemText", (PyCFunction)Dlg_GetDialogItemText, 1,
  980.      "(Handle item) -> (Str255 text)"},
  981.     {"SetDialogItemText", (PyCFunction)Dlg_SetDialogItemText, 1,
  982.      "(Handle item, Str255 text) -> None"},
  983.     {"NewColorDialog", (PyCFunction)Dlg_NewColorDialog, 1,
  984.      "(Rect boundsRect, Str255 title, Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon, Handle items) -> (DialogPtr _rv)"},
  985.     {"GetAlertStage", (PyCFunction)Dlg_GetAlertStage, 1,
  986.      "() -> (short _rv)"},
  987.     {"ResetAlertStage", (PyCFunction)Dlg_ResetAlertStage, 1,
  988.      "() -> None"},
  989.     {"SetDialogFont", (PyCFunction)Dlg_SetDialogFont, 1,
  990.      "(short value) -> None"},
  991.     {NULL, NULL, 0}
  992. };
  993.  
  994.  
  995.  
  996.  
  997. void initDlg()
  998. {
  999.     PyObject *m;
  1000.     PyObject *d;
  1001.  
  1002.  
  1003.  
  1004.  
  1005.     m = Py_InitModule("Dlg", Dlg_methods);
  1006.     d = PyModule_GetDict(m);
  1007.     Dlg_Error = PyMac_GetOSErrException();
  1008.     if (Dlg_Error == NULL ||
  1009.         PyDict_SetItemString(d, "Error", Dlg_Error) != 0)
  1010.         Py_FatalError("can't initialize Dlg.Error");
  1011. }
  1012.  
  1013. /* ========================= End module Dlg ========================= */
  1014.  
  1015.